/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kylingroup.J2SE.Thread;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;
import java.lang.Integer;
/**
 *
 * @author kylin
 */
public class TestFutureTask {
    public static void main(String args[]){
        TestFutureTask test=new TestFutureTask();
        FutureTask<Integer> task=new FutureTask<Integer>((Callable<Integer>)()->{
            int i=0;
            for(;i<100;i++){
                System.out.println(Thread.currentThread().getName()+" 的循环变量i的值:"+i);
            }
            return i;
        });
        for(int i=0;i<100;i++){
            System.out.println(Thread.currentThread().getName()+" 的循环变量i的值："+i);
            if(i==20){
                Thread th=new Thread(task,"有返回值的线程");
                th.start();
            }
        }
        try{
            System.out.println("子线程的返回值:"+task.get());
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}
